<?php


require_once(D_DIR.'/vendor/smarty/Smarty.class.php');

class tpl extends Smarty {

	public function __construct() {
		parent::__construct();
		
		$this->template_dir	= D_DIR.'/cache/template_dir';

		$this->compile_dir	= D_DIR.'/cache/compile_dir';

		$this->cache_dir	= D_DIR.'/cache/cache_dir';

		$this->left_delimiter	= '{-';
		$this->right_delimiter	= '-}';


		$this->assign('sess_name' , session_name());
		$this->assign('sess_id' , session_id());
	}


	public function & load() {	
		$args = func_get_args();
		$path	= D::$user->path();
		foreach($args as $arg){
			$this->assign( $arg,  file_get_contents(  $path.'/'. $arg .'.js'));
		}
		return $this;
	}

	public function & display( $file = false) {
		if( empty( $file ) ){
			$file	= basename($_SERVER["SCRIPT_NAME"]);
			$file	= substr($file, 0, -4);
			$file	= B_DIR .'/' . $file .'.tpl.htm';
		}
		parent::display($file);
		return $this;
	}

	public function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null){
		$_compile_dir_sep =  $this->use_sub_dirs ? DIRECTORY_SEPARATOR : '^';
		$_return = $auto_base . DIRECTORY_SEPARATOR;

		if(isset($auto_id)) {
			$auto_id	= str_replace('%7C',$_compile_dir_sep,( urlencode($auto_id)));
			$_return	.= $auto_id . $_compile_dir_sep;
		}

		if(isset($auto_source)) {
			$_filename	= urlencode( str_replace('/','_',$auto_source));
			$_crc32		= sprintf('%08X', crc32($auto_source));
			$_crc32		= substr($_crc32, 0, 2) . $_compile_dir_sep .
						substr($_crc32, 0, 3) . $_compile_dir_sep . $_crc32;
			$_return	.=  $_filename . '_%%' . $_crc32 . '%%';
		}
		return $_return;
	}
}
?>
